import os, time
from selenium import webdriver

chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"  # 浏览器驱动位置
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.implicitly_wait(10)
driver.get("http://www.baidu.com")
# 多窗口切换
search_windows = driver.current_window_handle

driver.find_element_by_partial_link_text('京公网安备').click()

all_handles = driver.window_handles
# time.sleep(2)
for handle in all_handles:
    driver.switch_to.window(handle)
    if handle != search_windows:
        print('now gongan window')
        time.sleep(2)
    else:
        print('now search window')
        time.sleep(2)
driver.quit()
